package Search;

import java.sql.*;

public class CheckDuplicate {

    String url = "jdbc:mysql://127.0.0.1:3306/nox?useUnicode=true&characterEncoding=UTF-8&userSSL=false&serverTimezone=GMT%2B8";
    String user = "root";
    String password = "Mi20030610.";
    public boolean check(String id,int k) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection Conn = DriverManager.getConnection(url, user, password);

        if(k==1)
        {
            //如果k为1，代表是用户id是9位
            String sql="select *from userinformation where id=?;";
            PreparedStatement operation=Conn.prepareStatement(sql);
            operation.setString(1,id);

            ResultSet resultSet=operation.executeQuery();
            if(resultSet.next())
            {
                operation.close();
                Conn.close();
                return false;
            }
        }
        else
        {
            //如果k为2，代表是群聊是10位
            String sql="select *from chat_room_list where group_id=?;";
            PreparedStatement operation=Conn.prepareStatement(sql);
            operation.setString(1,id);

            ResultSet resultSet=operation.executeQuery();
            if(resultSet.next())
            {
                operation.close();
                Conn.close();
                return false;
            }
        }
        return true;
    }
}
